<?php
namespace backend\controllers;

use common\models\BaseModels;
use common\models\kaoguobao\Order;
use common\services\OrderService;

/**
 * MenuUserController implements the CRUD actions for MenuUser model.
 */
class OrderController extends BaseExtendController
{
    public $where = ['is_valid = ' . BaseModels::MODEL_IS_VALID];

    /**
     * <?= Inflector::camel2words(StringHelper::basename($generator->modelClass)); ?> */
    public function settings(){
        return array( "title" => "订单列表",'pk' => 'id', 'model' => new Order());
    }

    public function actionOrderHandle($id)
    {
        $mode        = Order::findOne($id);
        $orderStatus = $mode->order_status;
        switch ($orderStatus) {
            case (Order::ORDER_STATUS_UP_PROOF):            // 用户凭证已上传
                return $this->render('order-voucher', [
                    'model' => OrderService::orderVoucher($id)
                ]);
                break;
            case (Order::ORDER_STATUS_HANDLED):             // 后台审核已通过处理红包或赔付业务
                return 2222;
                break;
            case (Order::ORDER_STATUS_PAYMENT):             // 赔付成功后订单业务回调
                return 5555;
                break;
            default:
                break;
        }
    }

    /**
     * 理赔凭证审核
     * @param $id
     * @param $orderStatus
     * @return mixed|string
     */
    public function actionVoucherHandle($id, $orderStatus)
    {
        $mode = Order::findOne($id);
        if(!empty($mode)){
            $mode->order_status = $orderStatus;
            if($mode->save()){
                return $this->redirect(['index']);
            }
        }
        return parent::actionIndex();
    }


}